unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBCtrls, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, turniertools,
  Mask;

type
  TForm6 = class(TForm)
    qMatchEdit: TZQuery;
    qMatchEditDS: TDataSource;
    guestCCB: TZQuery;
    guestCDS: TDataSource;
    Label1: TLabel;
    Label2: TLabel;
    speichernB: TButton;
    DBText1: TDBText;
    DBText2: TDBText;
    heimT: TEdit;
    gastT: TEdit;
    Label3: TLabel;
    queryStage: TZQuery;
    queryStageDS: TDataSource;
    ZQuery1: TZQuery;
    DataSource1: TDataSource;
    procedure speichernBClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

uses Unit1,Unit5,Unit4;

procedure TForm6.FormShow(Sender: TObject);
begin
  heimT.Text:=Form4.queryMatch.FieldByName('HomeG').Text;
  gastT.Text:=Form4.queryMatch.FieldByName('GuestG').Text;
end;

procedure TForm6.speichernBClick(Sender: TObject);
var h,g,matchId:integer;
    w,query:string;
begin
  h:=StrToInt(heimT.Text);
  g:=StrToInt(gastT.Text);

  if (h>g) then w:='1'
  else if (h<g) then w:='2'
       else if (h=g) then w:='3';

  matchId:=Form4.queryMatch.FieldByName('MatchId').AsInteger;
  query:=createSqlMatchEditStr(IntToStr(matchId));
  qMatchEdit.SQL.Clear;
  qMatchEdit.SQL.Add(query);
  qMatchEdit.Active:=true;
  qMatchEdit.Edit;
  qMatchEdit.FieldByName('winner').Text:=w;
  qMatchEdit.FieldByName('homeG').Text:=heimT.Text;
  qMatchEdit.FieldByName('guestG').Text:=gastT.Text;
  qMatchEdit.Post;

  Form4.queryMatch.Refresh;
  close;


end;

end.
